package com.yellowpage.common;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yellowpage.ca.dao.ConfigurationDao;
import com.yellowpage.ca.data.Configuration;

public class ConfigurationImpl implements
		com.yellowpage.white.common.Configuration {

	private ConfigurationDao configurationDao;

	/**
	 * @param configurationDao
	 *            the configurationDao to set
	 */
	public void setConfigurationDao(ConfigurationDao configurationDao) {
		this.configurationDao = configurationDao;
	}

	/**
	 * GetMap by Configuration
	 * 
	 * @param type
	 * @return
	 */
	public Map getConfigByType(String type) {
		Map<String, String> map = new HashMap<String, String>();
		try {
			List<Configuration> configs = configurationDao.getConfigurationsByType(type);
			for (Configuration cof : configs) {
				map.put(cof.getCode(), cof.getValue());
			}
			return map;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}	

	public String getValue(String key){
		return configurationDao.getConfigValue(key);
	}
	
}
